<template>
	<view>
		<view class="address-choose-box" v-if="!addStr">
			<button @click="btnChooseAddress" type="primary" size="mini" class="btnChooseAddress">请选择收货地址+</button>
		</view>
		<view @click="btnChooseAddress" v-if="addStr" class="address-info-box">
			<view class="row1">
				<view class="row1-left">
					<view class="username"> 收获员: {{address.userName}}
						
					</view>
				</view>
				<view class="row1-right">
					<view class="phone">
							电话: {{address.telNumber}}
					</view>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<view class="row2">
				<view class="row2-left">
					收货地址:
				</view>
				<view class="row2-right"> {{addStr}}
					<!-- {{address.provinceName}} {{address.cityName}} {{address.countyName}} {{address.detailInfo}} -->
				</view>
			</view>
		</view>
		
		<image src="../static/cart_border@2x.png" class="address-border"></image>
	</view>
</template>

<script>
	import {mapState,mapMutations } from 'vuex'
	export default {
		name:"my-address",
		data() {
			return {
				// address:{}
			};
		},
		methods: {
			...mapMutations('m_user',['updateAddress','saveAddressToStorage']),
			
			async btnChooseAddress(){
				const [err,succ] = await uni.chooseAddress().catch(error => err)
				
				if (err === null && succ.errMsg==='chooseAddress:ok') {
					// console.log(succ)
					// this.address = succ;
					this.updateAddress(succ);
					this.saveAddressToStorage(succ)
				}
			}
		},
		computed: {
			...mapState('m_user',['address']),
			addStr() {
				if (!this.address.provinceName) return ''
				return this.address.provinceName + this.address.cityName + this.address.countyName +  this.address.detailInfo;
				
			}
		}
	}
</script>

<style lang="scss">
	.address-info-box {
		font-size: 15px;
	}
	.address-border {
		display: block;
		width: 100%;
		height: 5px;
	}
	.address-choose-box {
		height: 90px;
		text-align: center;
		align-items: center;
		justify-content: center;
		display: flex;
	}
	
	.row1 {
	
		display: flex;
		justify-content: space-between;
		// flex-wrap: nowrap;
		margin: 10px 10px;
		
		
	}
	.row2-left {
		white-space: nowrap;
	}
	.row2 {
		display: flex;
		margin: 10px 10px;
		// justify-content: space-between;
		align-items: center;
		
	}
	.row1-right {
		display: flex;
		flex-wrap: nowrap;
		
	}
</style>
